package org.bigmarketapi.projectreview.concurrent;

import java.util.concurrent.locks.LockSupport;

/**
 * @BelongsProject: ProjectReview
 * @BelongsPackage: org.bigmarketapi.projectreview.concurrent
 * @Author: dujiaqi
 * @CreateTime: 2024-08-14  15:39
 * @Description: TODO
 * @Version: 1.0
 */
public class PrintABC {
     private static Thread threadA,threadB,threadC;

    public static void main(String[] args) {
        threadA=new Thread(()->{
            for (int i = 0; i < 10; i++) {
                System.out.print(Thread.currentThread().getName());
                //唤醒threadB
                LockSupport.unpark(threadC);
                //当前线程阻塞
                LockSupport.park();
            }
        },"A");
        threadB=new Thread(()->{
            for (int i = 0; i < 10; i++) {
                System.out.print(Thread.currentThread().getName());
                //唤醒线程threadC
                LockSupport.unpark(threadA);
                //阻塞当前线程
                LockSupport.park();
            }
        },"B");
        threadC=new Thread(()->{
            for (int i = 0; i < 10; i++) {
                System.out.print(Thread.currentThread().getName());
                //唤醒线程A
                LockSupport.unpark(threadB);
                //阻塞当前线程
                LockSupport.park();
            }
        },"C");
        threadA.start();
        threadB.start();
        threadC.start();
    }
}
